package com.pocket.demo.leetcode;

/**
 * https://leetcode.cn/problems/move-zeroes/?envType=study-plan-v2&envId=top-100-liked
 * @author zhaozhile
 */
public class _283_Array_MoveZeroes {

    public static int[] moveZeroes(int[] nums) {
        if (nums == null || nums.length == 0){
            return nums;
        }
        int m = 0;
        int n = 0;
        for (; m < nums.length; ++m) {
            if (nums[m] != 0){
                nums[n] = nums[m];
                n++;
            }
            if (m == nums.length - 1){
                for (; n < nums.length; n++){
                    nums[n] = 0;
                }
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] nums = {2, 1, 0, 3, 12};
        for (int n : moveZeroes(nums)){
            System.out.println(n);
        }
    }

}
